package com.jiyi.easemob.util;


import android.content.Context;
import android.content.Intent;

import com.hyphenate.easeui.controller.EaseUI;
import com.swift.maintenance.activity.LoginActivity;
import com.swift.maintenance.utils.UserInfoUtil;
import com.swift.utils.ActivityUtil;
import com.swift.maintenance.utils.JPushUtil;
import com.swift.utils.SPUtils;


public class UserHelp {
	private static UserHelp instance = null;

	public synchronized static UserHelp getInstance() {
		if (instance == null) {
			instance = new UserHelp();
		}
		return instance;
	}

	/**
	 * author hym
	 * desc 清除用户信息
	 * 2016-8-16
	 * @param context
	 */
	public void clearUser(Context context)
	{
		clearUser(context,false);
	}

	/**
	 * author hym
	 * desc 退出云上登录，重置属性，并且退出环信登录
	 * 2016-8-16
	 * @param context
	 * @param isEaseLoginout
	 */
	public void clearUser(Context context,boolean isEaseLoginout)
	{
		SPUtils.getInstance().put("isLogin", false);
		SPUtils.getInstance().put("memberId", "");
		SPUtils.getInstance().put("token", "");
		UserInfoUtil.clearUserInfo();
		new JPushUtil(context,"").setJPushAlias();
		//环信通知取消
		EaseUI.getInstance().getNotifier().reset();
		if (isEaseLoginout) {
			//环信用户注销
			EaseMobHelp.getInstance().logout();
		}

		ActivityUtil.getInstances().exit();
		context.startActivity(new Intent(context,LoginActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
	}
}
